﻿namespace Sai.Core.Rules
{
	using Sai.Core.Introspection;

	public class CheckTypesObsolete : IAssemblyRule
	{
        public void Validate(IntrospectedAssembly first, IntrospectedAssembly second, IAssemblyDifference assemblyDifference)
		{
			// look for newly obsolete types
			var commonTypes = second.TypesInCommonWith(first);

			var factory = new TypeDifferenceFactory();

			foreach (var commonType in commonTypes)
			{
				var firstType = first.Lookup(commonType);
				var secondType = second.Lookup(commonType);

				if (secondType.IsObsolete && !firstType.IsObsolete)
				{
					string message = string.Empty;

					if (!string.IsNullOrEmpty(secondType.ObsoleteReason))
					{
						message = secondType.ObsoleteReason;
					}

					assemblyDifference.Obsolete(firstType.TypeName, message);
				}
			}
		}
	}
}
